/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		   */
/*																   */
/*	NAME	  = t__sqlserver_bigint_add.c						   */
/*	NOTE	  = 												   */
/*	DATE	  = 2014/11/25 by geyh								   */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "../test_db2_comm.h"
#include <db2/db2_core.h>
#include <apmtest_comm.h>
#include <db2/config.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);

    Apm_packet *p_st_packet = NULL;
    struct timeval st_timestamp;
    st_timestamp.tv_sec = 1454549354L;
    st_timestamp.tv_usec = 123456L;
    CU_ASSERT_EQUAL(apmtest_create_apm_packet(&p_st_packet,
                                              (char *) "\x00\x89\xd0\x41\x00\x01\x00\x83\x10\x41\x00\x39\x11\x5e\x84\x82\xf2\x91\x83\x83\x6d\x81\x97\x97\x93\x89\x83\x81\xa3\x89\x96\x95\x40\x40\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\xf0\x17\xc3\xf0\xc1\xf8\xf0\xf1\xf6\xf5\x4b\x01\x4b\xe4\x79\xfa\xb5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16\x11\x6d\xe6\x89\x95\x60\xd7\xc3\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x00\x0c\x11\x5a\xd1\xc3\xc3\xf0\xf2\xf1\xf0\xf0\x00\x18\x14\x04\x14\x03\x00\x07\x24\x07\x00\x07\x24\x0f\x00\x07\x14\x40\x00\x07\x14\x74\x00\x05\x00\x0c\x11\x47\xd8\xc4\xc2\xf2\x61\xd1\xe5\xd4",
                                              137, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT,
                                              TEST_DB2_DST_PORT, st_timestamp), FR_SUCC);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 2), FR_SUCC);

    CU_ASSERT_EQUAL(db2_analysis(p_st_conn, p_st_packet, &st_hash_report), APM_L7_ANALYZE_TODO);

    frhash2_free(&st_hash_report, list_report_node_free);

    apmtest_destroy_apm_packet(&p_st_packet);

    test_db2_destroy_ct(&p_st_conn);

    return;
}

int add_suite_db2_analysis(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" db2_analysis()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
